



// This code is a generated code by a tool
// designed and coded by Shohdi Mohamed Elsheemy ( shohdi@gmail.com )            

using System;
using System.Collections.Generic;
using System.Web;
using System.Data.Common;
using Shohdi.DataHandler;
using System.Data;




namespace DatabaseComponent
{
    
    public partial class TicketDB
    {
         string _Connection = "";


        public string Connection
        {
            get { return _Connection; }
            set { _Connection = value; }
        }


       
         string _Provider = "System.Data.SqlClient";

        
        public string Provider
        {
            get { return _Provider; }
            set { _Provider = value; }
        }



        public TicketDB()
        {
        }

        public TicketDB(string __Connection,params string [] __Provider)
        {

            if (__Provider.Length > 0)
                _Provider = __Provider[0];

            _Connection = __Connection;
            
        }




        public List<Ticket> Select(ClassDataHandler con, string strTop, string strWhere, params DbParameter[] whereParams)
        {
            if (whereParams == null)
                whereParams = new DbParameter[0];

            List<Ticket> lstRet = new List<Ticket>();

            string strQuery = " select " + strTop  + " * from dbo.[Ticket]  " ;

            if (strWhere != "")
            {
                strQuery = strQuery + "  " + strWhere;
            }

            DbDataReader dr = con.SelectDataReader(strQuery, CommandType.Text, whereParams);


            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    Ticket obj = new Ticket();
 if (dr["ID"] != DBNull.Value)
                    {
                        obj.ID = (System.Int64)dr["ID"];
                    }
                    else
                    {
                        obj.ID = -1;
                    } 
 if (dr["EmployeeID"] != DBNull.Value)
                    {
                        obj.EmployeeID = (System.Int64)dr["EmployeeID"];
                    }
                    else
                    {
                        obj.EmployeeID = -1;
                    } 
 if (dr["StartTime"] != DBNull.Value)
                    {
                        obj.StartTime = (System.DateTime)dr["StartTime"];
                    }
                    else
                    {
                        obj.StartTime = DateTime.Now;
                    } 
 if (dr["ModifyTime"] != DBNull.Value)
                    {
                        obj.ModifyTime = (System.DateTime)dr["ModifyTime"];
                    }
                    else
                    {
                        obj.ModifyTime = DateTime.Now;
                    } 
 if (dr["RequestTypeID"] != DBNull.Value)
                    {
                        obj.RequestTypeID = (System.Int64)dr["RequestTypeID"];
                    }
                    else
                    {
                        obj.RequestTypeID = -1;
                    } 
 if (dr["Title"] != DBNull.Value)
                    {
                        obj.Title = (System.String)dr["Title"];
                    }
                    else
                    {
                        obj.Title = "";
                    } 
 if (dr["Details"] != DBNull.Value)
                    {
                        obj.Details = (System.String)dr["Details"];
                    }
                    else
                    {
                        obj.Details = "";
                    } 
 if (dr["StatusID"] != DBNull.Value)
                    {
                        obj.StatusID = (System.Int64)dr["StatusID"];
                    }
                    else
                    {
                        obj.StatusID = -1;
                    } 
 if (dr["OperatorID"] != DBNull.Value)
                    {
                        obj.OperatorID = (System.Int64?)dr["OperatorID"];
                    }
                    else
                    {
                        obj.OperatorID = null;
                    } 
 if (dr["PeriorityID"] != DBNull.Value)
                    {
                        obj.PeriorityID = (System.Int64)dr["PeriorityID"];
                    }
                    else
                    {
                        obj.PeriorityID = -1;
                    } 
 if (dr["Note"] != DBNull.Value)
                    {
                        obj.Note = (System.String)dr["Note"];
                    }
                    else
                    {
                        obj.Note = "";
                    } 



                    lstRet.Add(obj);
                   

                }
            }

            dr.Close();


            return lstRet;
        }


        public List<Ticket> Select(string strTop, string strWhere, params DbParameter[] whereParams)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<Ticket> lstRet = Select(con, strTop, strWhere, whereParams);

            con.CloseConnection();

            return lstRet;
        }

        



        public void Insert(ClassDataHandler con , Ticket obj)
        {
            
            

                    DbParameter prmEmployeeID = con.createParameter();
                    prmEmployeeID.ParameterName = "@EmployeeID";
                    prmEmployeeID.DbType =DbType.Int64;
                    if (obj.EmployeeID == null)
                    {
                        prmEmployeeID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmEmployeeID.Value = obj.EmployeeID;
                    }
                

                    


                    DbParameter prmStartTime = con.createParameter();
                    prmStartTime.ParameterName = "@StartTime";
                    prmStartTime.DbType =DbType.DateTime;
                    if (obj.StartTime == null)
                    {
                        prmStartTime.Value = DBNull.Value;
                    }
                    else
                    {
                        prmStartTime.Value = obj.StartTime;
                    }
                

                    


                    DbParameter prmModifyTime = con.createParameter();
                    prmModifyTime.ParameterName = "@ModifyTime";
                    prmModifyTime.DbType =DbType.DateTime;
                    if (obj.ModifyTime == null)
                    {
                        prmModifyTime.Value = DBNull.Value;
                    }
                    else
                    {
                        prmModifyTime.Value = obj.ModifyTime;
                    }
                

                    


                    DbParameter prmRequestTypeID = con.createParameter();
                    prmRequestTypeID.ParameterName = "@RequestTypeID";
                    prmRequestTypeID.DbType =DbType.Int64;
                    if (obj.RequestTypeID == null)
                    {
                        prmRequestTypeID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmRequestTypeID.Value = obj.RequestTypeID;
                    }
                

                    


                    DbParameter prmTitle = con.createParameter();
                    prmTitle.ParameterName = "@Title";
                    prmTitle.DbType =DbType.String;
                    if (obj.Title == null)
                    {
                        prmTitle.Value = DBNull.Value;
                    }
                    else
                    {
                        prmTitle.Value = obj.Title;
                    }
                

                    


                    DbParameter prmDetails = con.createParameter();
                    prmDetails.ParameterName = "@Details";
                    prmDetails.DbType =DbType.String;
                    if (obj.Details == null)
                    {
                        prmDetails.Value = DBNull.Value;
                    }
                    else
                    {
                        prmDetails.Value = obj.Details;
                    }
                

                    


                    DbParameter prmStatusID = con.createParameter();
                    prmStatusID.ParameterName = "@StatusID";
                    prmStatusID.DbType =DbType.Int64;
                    if (obj.StatusID == null)
                    {
                        prmStatusID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmStatusID.Value = obj.StatusID;
                    }
                

                    


                    DbParameter prmOperatorID = con.createParameter();
                    prmOperatorID.ParameterName = "@OperatorID";
                    prmOperatorID.DbType =DbType.Int64;
                    if (obj.OperatorID == null)
                    {
                        prmOperatorID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmOperatorID.Value = obj.OperatorID;
                    }
                

                    


                    DbParameter prmPeriorityID = con.createParameter();
                    prmPeriorityID.ParameterName = "@PeriorityID";
                    prmPeriorityID.DbType =DbType.Int64;
                    if (obj.PeriorityID == null)
                    {
                        prmPeriorityID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmPeriorityID.Value = obj.PeriorityID;
                    }
                

                    


                    DbParameter prmNote = con.createParameter();
                    prmNote.ParameterName = "@Note";
                    prmNote.DbType =DbType.String;
                    if (obj.Note == null)
                    {
                        prmNote.Value = DBNull.Value;
                    }
                    else
                    {
                        prmNote.Value = obj.Note;
                    }
                

                    


           



            string strQuery = " insert into dbo.[Ticket] ([EmployeeID],[StartTime],[ModifyTime],[RequestTypeID],[Title],[Details],[StatusID],[OperatorID],[PeriorityID],[Note]) VALUES (@EmployeeID,@StartTime,@ModifyTime,@RequestTypeID,@Title,@Details,@StatusID,@OperatorID,@PeriorityID,@Note) ; select SCOPE_IDENTITY() ";
 object scope = con.ExecuteScalar(strQuery, CommandType.Text, prmEmployeeID,prmStartTime,prmModifyTime,prmRequestTypeID,prmTitle,prmDetails,prmStatusID,prmOperatorID,prmPeriorityID,prmNote);


                    try
                    {
                        obj.ID = System.Int64.Parse(scope.ToString());
                    }
                    catch
                    {
                        obj.ID = -1;
                    }


                    


           

        }



        public void Insert(Ticket obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Insert(con,obj);


            con.CloseConnection();
        }




        public void Update(ClassDataHandler con, Ticket obj)
        {
            
            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


                    DbParameter prmEmployeeID = con.createParameter();
                    prmEmployeeID.ParameterName = "@EmployeeID";
                    prmEmployeeID.DbType =DbType.Int64;
                    if (obj.EmployeeID == null)
                    {
                        prmEmployeeID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmEmployeeID.Value = obj.EmployeeID;
                    }
                

                    


                    DbParameter prmStartTime = con.createParameter();
                    prmStartTime.ParameterName = "@StartTime";
                    prmStartTime.DbType =DbType.DateTime;
                    if (obj.StartTime == null)
                    {
                        prmStartTime.Value = DBNull.Value;
                    }
                    else
                    {
                        prmStartTime.Value = obj.StartTime;
                    }
                

                    


                    DbParameter prmModifyTime = con.createParameter();
                    prmModifyTime.ParameterName = "@ModifyTime";
                    prmModifyTime.DbType =DbType.DateTime;
                    if (obj.ModifyTime == null)
                    {
                        prmModifyTime.Value = DBNull.Value;
                    }
                    else
                    {
                        prmModifyTime.Value = obj.ModifyTime;
                    }
                

                    


                    DbParameter prmRequestTypeID = con.createParameter();
                    prmRequestTypeID.ParameterName = "@RequestTypeID";
                    prmRequestTypeID.DbType =DbType.Int64;
                    if (obj.RequestTypeID == null)
                    {
                        prmRequestTypeID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmRequestTypeID.Value = obj.RequestTypeID;
                    }
                

                    


                    DbParameter prmTitle = con.createParameter();
                    prmTitle.ParameterName = "@Title";
                    prmTitle.DbType =DbType.String;
                    if (obj.Title == null)
                    {
                        prmTitle.Value = DBNull.Value;
                    }
                    else
                    {
                        prmTitle.Value = obj.Title;
                    }
                

                    


                    DbParameter prmDetails = con.createParameter();
                    prmDetails.ParameterName = "@Details";
                    prmDetails.DbType =DbType.String;
                    if (obj.Details == null)
                    {
                        prmDetails.Value = DBNull.Value;
                    }
                    else
                    {
                        prmDetails.Value = obj.Details;
                    }
                

                    


                    DbParameter prmStatusID = con.createParameter();
                    prmStatusID.ParameterName = "@StatusID";
                    prmStatusID.DbType =DbType.Int64;
                    if (obj.StatusID == null)
                    {
                        prmStatusID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmStatusID.Value = obj.StatusID;
                    }
                

                    


                    DbParameter prmOperatorID = con.createParameter();
                    prmOperatorID.ParameterName = "@OperatorID";
                    prmOperatorID.DbType =DbType.Int64;
                    if (obj.OperatorID == null)
                    {
                        prmOperatorID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmOperatorID.Value = obj.OperatorID;
                    }
                

                    


                    DbParameter prmPeriorityID = con.createParameter();
                    prmPeriorityID.ParameterName = "@PeriorityID";
                    prmPeriorityID.DbType =DbType.Int64;
                    if (obj.PeriorityID == null)
                    {
                        prmPeriorityID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmPeriorityID.Value = obj.PeriorityID;
                    }
                

                    


                    DbParameter prmNote = con.createParameter();
                    prmNote.ParameterName = "@Note";
                    prmNote.DbType =DbType.String;
                    if (obj.Note == null)
                    {
                        prmNote.Value = DBNull.Value;
                    }
                    else
                    {
                        prmNote.Value = obj.Note;
                    }
                

                    


           



            string strQuery = " update dbo.[Ticket] set [EmployeeID]=@EmployeeID,[StartTime]=@StartTime,[ModifyTime]=@ModifyTime,[RequestTypeID]=@RequestTypeID,[Title]=@Title,[Details]=@Details,[StatusID]=@StatusID,[OperatorID]=@OperatorID,[PeriorityID]=@PeriorityID,[Note]=@Note where  [ID]=@ID  ";

            con.ExecuteNonQuery(strQuery, CommandType.Text,prmID,prmEmployeeID,prmStartTime,prmModifyTime,prmRequestTypeID,prmTitle,prmDetails,prmStatusID,prmOperatorID,prmPeriorityID,prmNote);

            

        }


        public void Update(Ticket obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Update(con, obj);


            con.CloseConnection();
        }



        public void Delete(ClassDataHandler con, Ticket obj)
        {

            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


           



           



            string strQuery = " delete from dbo.[Ticket]  where  [ID]=@ID  "; 
                        con.ExecuteNonQuery(strQuery, CommandType.Text,prmID );  

             



        }


        public void Delete( Ticket obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            Delete(con, obj);

            con.CloseConnection();
        }





                    public List<Ticket> getTicketByID(ClassDataHandler con,System.Int64 ID)
                    {
                        List<Ticket> lstRet = new List<Ticket>();


                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType = DbType.Int64;
                        if (ID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmID.Value = ID;
                        }


                        lstRet = Select(con, "" , " where [ID]=@ID ", prmID);



                        return lstRet;

                    }


                    public List<Ticket> getTicketByID(System.Int64 ID)
                    {
                        List<Ticket> lstRet = new List<Ticket>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getTicketByID(con, ID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Ticket> getTicketByEmployeeID(ClassDataHandler con,System.Int64 EmployeeID)
                    {
                        List<Ticket> lstRet = new List<Ticket>();


                        DbParameter prmEmployeeID = con.createParameter();
                        prmEmployeeID.ParameterName = "@EmployeeID";
                        prmEmployeeID.DbType = DbType.Int64;
                        if (EmployeeID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmEmployeeID.Value = EmployeeID;
                        }


                        lstRet = Select(con, "" , " where [EmployeeID]=@EmployeeID ", prmEmployeeID);



                        return lstRet;

                    }


                    public List<Ticket> getTicketByEmployeeID(System.Int64 EmployeeID)
                    {
                        List<Ticket> lstRet = new List<Ticket>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getTicketByEmployeeID(con, EmployeeID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Ticket> getTicketByStartTime(ClassDataHandler con,System.DateTime StartTime)
                    {
                        List<Ticket> lstRet = new List<Ticket>();


                        DbParameter prmStartTime = con.createParameter();
                        prmStartTime.ParameterName = "@StartTime";
                        prmStartTime.DbType = DbType.DateTime;
                        if (StartTime == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmStartTime.Value = StartTime;
                        }


                        lstRet = Select(con, "" , " where [StartTime]=@StartTime ", prmStartTime);



                        return lstRet;

                    }


                    public List<Ticket> getTicketByStartTime(System.DateTime StartTime)
                    {
                        List<Ticket> lstRet = new List<Ticket>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getTicketByStartTime(con, StartTime);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Ticket> getTicketByModifyTime(ClassDataHandler con,System.DateTime ModifyTime)
                    {
                        List<Ticket> lstRet = new List<Ticket>();


                        DbParameter prmModifyTime = con.createParameter();
                        prmModifyTime.ParameterName = "@ModifyTime";
                        prmModifyTime.DbType = DbType.DateTime;
                        if (ModifyTime == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmModifyTime.Value = ModifyTime;
                        }


                        lstRet = Select(con, "" , " where [ModifyTime]=@ModifyTime ", prmModifyTime);



                        return lstRet;

                    }


                    public List<Ticket> getTicketByModifyTime(System.DateTime ModifyTime)
                    {
                        List<Ticket> lstRet = new List<Ticket>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getTicketByModifyTime(con, ModifyTime);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Ticket> getTicketByRequestTypeID(ClassDataHandler con,System.Int64 RequestTypeID)
                    {
                        List<Ticket> lstRet = new List<Ticket>();


                        DbParameter prmRequestTypeID = con.createParameter();
                        prmRequestTypeID.ParameterName = "@RequestTypeID";
                        prmRequestTypeID.DbType = DbType.Int64;
                        if (RequestTypeID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmRequestTypeID.Value = RequestTypeID;
                        }


                        lstRet = Select(con, "" , " where [RequestTypeID]=@RequestTypeID ", prmRequestTypeID);



                        return lstRet;

                    }


                    public List<Ticket> getTicketByRequestTypeID(System.Int64 RequestTypeID)
                    {
                        List<Ticket> lstRet = new List<Ticket>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getTicketByRequestTypeID(con, RequestTypeID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Ticket> getTicketByTitle(ClassDataHandler con,System.String Title)
                    {
                        List<Ticket> lstRet = new List<Ticket>();


                        DbParameter prmTitle = con.createParameter();
                        prmTitle.ParameterName = "@Title";
                        prmTitle.DbType = DbType.String;
                        if (Title == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmTitle.Value = Title;
                        }


                        lstRet = Select(con, "" , " where [Title]=@Title ", prmTitle);



                        return lstRet;

                    }


                    public List<Ticket> getTicketByTitle(System.String Title)
                    {
                        List<Ticket> lstRet = new List<Ticket>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getTicketByTitle(con, Title);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Ticket> getTicketByDetails(ClassDataHandler con,System.String Details)
                    {
                        List<Ticket> lstRet = new List<Ticket>();


                        DbParameter prmDetails = con.createParameter();
                        prmDetails.ParameterName = "@Details";
                        prmDetails.DbType = DbType.String;
                        if (Details == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmDetails.Value = Details;
                        }


                        lstRet = Select(con, "" , " where [Details]=@Details ", prmDetails);



                        return lstRet;

                    }


                    public List<Ticket> getTicketByDetails(System.String Details)
                    {
                        List<Ticket> lstRet = new List<Ticket>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getTicketByDetails(con, Details);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Ticket> getTicketByStatusID(ClassDataHandler con,System.Int64 StatusID)
                    {
                        List<Ticket> lstRet = new List<Ticket>();


                        DbParameter prmStatusID = con.createParameter();
                        prmStatusID.ParameterName = "@StatusID";
                        prmStatusID.DbType = DbType.Int64;
                        if (StatusID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmStatusID.Value = StatusID;
                        }


                        lstRet = Select(con, "" , " where [StatusID]=@StatusID ", prmStatusID);



                        return lstRet;

                    }


                    public List<Ticket> getTicketByStatusID(System.Int64 StatusID)
                    {
                        List<Ticket> lstRet = new List<Ticket>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getTicketByStatusID(con, StatusID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Ticket> getTicketByOperatorID(ClassDataHandler con,System.Int64? OperatorID)
                    {
                        List<Ticket> lstRet = new List<Ticket>();


                        DbParameter prmOperatorID = con.createParameter();
                        prmOperatorID.ParameterName = "@OperatorID";
                        prmOperatorID.DbType = DbType.Int64;
                        if (OperatorID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmOperatorID.Value = OperatorID;
                        }


                        lstRet = Select(con, "" , " where [OperatorID]=@OperatorID ", prmOperatorID);



                        return lstRet;

                    }


                    public List<Ticket> getTicketByOperatorID(System.Int64? OperatorID)
                    {
                        List<Ticket> lstRet = new List<Ticket>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getTicketByOperatorID(con, OperatorID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Ticket> getTicketByPeriorityID(ClassDataHandler con,System.Int64 PeriorityID)
                    {
                        List<Ticket> lstRet = new List<Ticket>();


                        DbParameter prmPeriorityID = con.createParameter();
                        prmPeriorityID.ParameterName = "@PeriorityID";
                        prmPeriorityID.DbType = DbType.Int64;
                        if (PeriorityID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmPeriorityID.Value = PeriorityID;
                        }


                        lstRet = Select(con, "" , " where [PeriorityID]=@PeriorityID ", prmPeriorityID);



                        return lstRet;

                    }


                    public List<Ticket> getTicketByPeriorityID(System.Int64 PeriorityID)
                    {
                        List<Ticket> lstRet = new List<Ticket>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getTicketByPeriorityID(con, PeriorityID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Ticket> getTicketByNote(ClassDataHandler con,System.String Note)
                    {
                        List<Ticket> lstRet = new List<Ticket>();


                        DbParameter prmNote = con.createParameter();
                        prmNote.ParameterName = "@Note";
                        prmNote.DbType = DbType.String;
                        if (Note == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmNote.Value = Note;
                        }


                        lstRet = Select(con, "" , " where [Note]=@Note ", prmNote);



                        return lstRet;

                    }


                    public List<Ticket> getTicketByNote(System.String Note)
                    {
                        List<Ticket> lstRet = new List<Ticket>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getTicketByNote(con, Note);

                        con.CloseConnection();

                        return lstRet;

                    }



                

            
public List<Ticket> Search(ClassDataHandler con, Ticket obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID AND ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.EmployeeID != -1)
                    {
                        DbParameter prmEmployeeID = con.createParameter();
                        prmEmployeeID.ParameterName = "@EmployeeID";
                        prmEmployeeID.DbType =DbType.Int64;
                        if (obj.EmployeeID == null)
                        {
                            prmEmployeeID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmEmployeeID.Value = obj.EmployeeID;
                        }
                        strWhere += " [EmployeeID]=@EmployeeID AND ";
                        lstParameters.Add(prmEmployeeID);
                     }



                    

                    if (obj.StartTime != DateTime.Now)
                    {
                        DbParameter prmStartTime = con.createParameter();
                        prmStartTime.ParameterName = "@StartTime";
                        prmStartTime.DbType =DbType.DateTime;
                        if (obj.StartTime == null)
                        {
                            prmStartTime.Value = DBNull.Value;
                        }
                        else
                        {
                            prmStartTime.Value = obj.StartTime;
                        }
                        strWhere += " [StartTime]=@StartTime AND ";
                        lstParameters.Add(prmStartTime);
                     }



                    

                    if (obj.ModifyTime != DateTime.Now)
                    {
                        DbParameter prmModifyTime = con.createParameter();
                        prmModifyTime.ParameterName = "@ModifyTime";
                        prmModifyTime.DbType =DbType.DateTime;
                        if (obj.ModifyTime == null)
                        {
                            prmModifyTime.Value = DBNull.Value;
                        }
                        else
                        {
                            prmModifyTime.Value = obj.ModifyTime;
                        }
                        strWhere += " [ModifyTime]=@ModifyTime AND ";
                        lstParameters.Add(prmModifyTime);
                     }



                    

                    if (obj.RequestTypeID != -1)
                    {
                        DbParameter prmRequestTypeID = con.createParameter();
                        prmRequestTypeID.ParameterName = "@RequestTypeID";
                        prmRequestTypeID.DbType =DbType.Int64;
                        if (obj.RequestTypeID == null)
                        {
                            prmRequestTypeID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmRequestTypeID.Value = obj.RequestTypeID;
                        }
                        strWhere += " [RequestTypeID]=@RequestTypeID AND ";
                        lstParameters.Add(prmRequestTypeID);
                     }



                    

                    if (obj.Title != "")
                    {
                        DbParameter prmTitle = con.createParameter();
                        prmTitle.ParameterName = "@Title";
                        prmTitle.DbType =DbType.String;
                        if (obj.Title == null)
                        {
                            prmTitle.Value = DBNull.Value;
                        }
                        else
                        {
                            prmTitle.Value = obj.Title;
                        }
                        strWhere += " [Title]=@Title AND ";
                        lstParameters.Add(prmTitle);
                     }



                    

                    if (obj.Details != "")
                    {
                        DbParameter prmDetails = con.createParameter();
                        prmDetails.ParameterName = "@Details";
                        prmDetails.DbType =DbType.String;
                        if (obj.Details == null)
                        {
                            prmDetails.Value = DBNull.Value;
                        }
                        else
                        {
                            prmDetails.Value = obj.Details;
                        }
                        strWhere += " [Details]=@Details AND ";
                        lstParameters.Add(prmDetails);
                     }



                    

                    if (obj.StatusID != -1)
                    {
                        DbParameter prmStatusID = con.createParameter();
                        prmStatusID.ParameterName = "@StatusID";
                        prmStatusID.DbType =DbType.Int64;
                        if (obj.StatusID == null)
                        {
                            prmStatusID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmStatusID.Value = obj.StatusID;
                        }
                        strWhere += " [StatusID]=@StatusID AND ";
                        lstParameters.Add(prmStatusID);
                     }



                    

                    if (obj.OperatorID != null)
                    {
                        DbParameter prmOperatorID = con.createParameter();
                        prmOperatorID.ParameterName = "@OperatorID";
                        prmOperatorID.DbType =DbType.Int64;
                        if (obj.OperatorID == null)
                        {
                            prmOperatorID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmOperatorID.Value = obj.OperatorID;
                        }
                        strWhere += " [OperatorID]=@OperatorID AND ";
                        lstParameters.Add(prmOperatorID);
                     }



                    

                    if (obj.PeriorityID != -1)
                    {
                        DbParameter prmPeriorityID = con.createParameter();
                        prmPeriorityID.ParameterName = "@PeriorityID";
                        prmPeriorityID.DbType =DbType.Int64;
                        if (obj.PeriorityID == null)
                        {
                            prmPeriorityID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmPeriorityID.Value = obj.PeriorityID;
                        }
                        strWhere += " [PeriorityID]=@PeriorityID AND ";
                        lstParameters.Add(prmPeriorityID);
                     }



                    

                    if (obj.Note != "")
                    {
                        DbParameter prmNote = con.createParameter();
                        prmNote.ParameterName = "@Note";
                        prmNote.DbType =DbType.String;
                        if (obj.Note == null)
                        {
                            prmNote.Value = DBNull.Value;
                        }
                        else
                        {
                            prmNote.Value = obj.Note;
                        }
                        strWhere += " [Note]=@Note AND ";
                        lstParameters.Add(prmNote);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("AND"));

                    

            

            List<Ticket> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<Ticket> Search(Ticket obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<Ticket> lstRet = Search(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                

            
public List<Ticket> SearchOrLike(ClassDataHandler con, Ticket obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID OR ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.EmployeeID != -1)
                    {
                        DbParameter prmEmployeeID = con.createParameter();
                        prmEmployeeID.ParameterName = "@EmployeeID";
                        prmEmployeeID.DbType =DbType.Int64;
                        if (obj.EmployeeID == null)
                        {
                            prmEmployeeID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmEmployeeID.Value = obj.EmployeeID;
                        }
                        strWhere += " [EmployeeID]=@EmployeeID OR ";
                        lstParameters.Add(prmEmployeeID);
                     }



                    

                    if (obj.StartTime != DateTime.Now)
                    {
                        DbParameter prmStartTime = con.createParameter();
                        prmStartTime.ParameterName = "@StartTime";
                        prmStartTime.DbType =DbType.DateTime;
                        if (obj.StartTime == null)
                        {
                            prmStartTime.Value = DBNull.Value;
                        }
                        else
                        {
                            prmStartTime.Value = obj.StartTime;
                        }
                        strWhere += " [StartTime]=@StartTime OR ";
                        lstParameters.Add(prmStartTime);
                     }



                    

                    if (obj.ModifyTime != DateTime.Now)
                    {
                        DbParameter prmModifyTime = con.createParameter();
                        prmModifyTime.ParameterName = "@ModifyTime";
                        prmModifyTime.DbType =DbType.DateTime;
                        if (obj.ModifyTime == null)
                        {
                            prmModifyTime.Value = DBNull.Value;
                        }
                        else
                        {
                            prmModifyTime.Value = obj.ModifyTime;
                        }
                        strWhere += " [ModifyTime]=@ModifyTime OR ";
                        lstParameters.Add(prmModifyTime);
                     }



                    

                    if (obj.RequestTypeID != -1)
                    {
                        DbParameter prmRequestTypeID = con.createParameter();
                        prmRequestTypeID.ParameterName = "@RequestTypeID";
                        prmRequestTypeID.DbType =DbType.Int64;
                        if (obj.RequestTypeID == null)
                        {
                            prmRequestTypeID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmRequestTypeID.Value = obj.RequestTypeID;
                        }
                        strWhere += " [RequestTypeID]=@RequestTypeID OR ";
                        lstParameters.Add(prmRequestTypeID);
                     }



                    

                    if (obj.Title != "")
                    {
                        DbParameter prmTitle = con.createParameter();
                        prmTitle.ParameterName = "@Title";
                        prmTitle.DbType =DbType.String;
                        if (obj.Title == null)
                        {
                            prmTitle.Value = DBNull.Value;
                        }
                        else
                        {
                            prmTitle.Value = obj.Title;
                        }
                        strWhere += " [Title] LIKE @Title OR ";
                        lstParameters.Add(prmTitle);
                     }



                    

                    if (obj.Details != "")
                    {
                        DbParameter prmDetails = con.createParameter();
                        prmDetails.ParameterName = "@Details";
                        prmDetails.DbType =DbType.String;
                        if (obj.Details == null)
                        {
                            prmDetails.Value = DBNull.Value;
                        }
                        else
                        {
                            prmDetails.Value = obj.Details;
                        }
                        strWhere += " [Details] LIKE @Details OR ";
                        lstParameters.Add(prmDetails);
                     }



                    

                    if (obj.StatusID != -1)
                    {
                        DbParameter prmStatusID = con.createParameter();
                        prmStatusID.ParameterName = "@StatusID";
                        prmStatusID.DbType =DbType.Int64;
                        if (obj.StatusID == null)
                        {
                            prmStatusID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmStatusID.Value = obj.StatusID;
                        }
                        strWhere += " [StatusID]=@StatusID OR ";
                        lstParameters.Add(prmStatusID);
                     }



                    

                    if (obj.OperatorID != null)
                    {
                        DbParameter prmOperatorID = con.createParameter();
                        prmOperatorID.ParameterName = "@OperatorID";
                        prmOperatorID.DbType =DbType.Int64;
                        if (obj.OperatorID == null)
                        {
                            prmOperatorID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmOperatorID.Value = obj.OperatorID;
                        }
                        strWhere += " [OperatorID]=@OperatorID OR ";
                        lstParameters.Add(prmOperatorID);
                     }



                    

                    if (obj.PeriorityID != -1)
                    {
                        DbParameter prmPeriorityID = con.createParameter();
                        prmPeriorityID.ParameterName = "@PeriorityID";
                        prmPeriorityID.DbType =DbType.Int64;
                        if (obj.PeriorityID == null)
                        {
                            prmPeriorityID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmPeriorityID.Value = obj.PeriorityID;
                        }
                        strWhere += " [PeriorityID]=@PeriorityID OR ";
                        lstParameters.Add(prmPeriorityID);
                     }



                    

                    if (obj.Note != "")
                    {
                        DbParameter prmNote = con.createParameter();
                        prmNote.ParameterName = "@Note";
                        prmNote.DbType =DbType.String;
                        if (obj.Note == null)
                        {
                            prmNote.Value = DBNull.Value;
                        }
                        else
                        {
                            prmNote.Value = obj.Note;
                        }
                        strWhere += " [Note] LIKE @Note OR ";
                        lstParameters.Add(prmNote);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("OR"));

                    

            

            List<Ticket> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<Ticket> SearchOrLike(Ticket obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<Ticket> lstRet = SearchOrLike(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                
        


       
        



    }
}











            